package com.controller;

import com.entity.Artical;
import com.service.AriticalService;
import com.service.impl.ArticalServerImpl;
import com.util.json.Result;
import com.util.servlet.BaseController;
import com.util.sql.PageModel;

import javax.servlet.annotation.WebServlet;
import java.util.List;

/*
 * 帖子管理
 */
//@WebServlet("/artical")
public class ArticalController extends BaseController {
     AriticalService articalServer = new ArticalServerImpl();

    /**
     * 发帖子
     * @param artical
     * @return
     */
    public String sendArtical(Artical artical){
        Artical p = articalServer.sendPost(artical);
        return p==null ? Result.fial("发帖失败") : Result.success();
    }
    //保存帖子
    public String saveArtical(Artical artical){
        try {
            Artical ar = articalServer.saveArtical(artical);
            return  ar == null ? Result.fial("保存失败") : Result.success();
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fial(e.getMessage());
        }

    }

    /**
     * 删除帖子
     * @param artical
     * @return
     */
    public String delPost(Artical artical){
        return "";
    }

    /**
     * 修改帖子
     * @param artical
     * @return
     */
    public String updatePost(Artical artical){
        return "";
    }

    /**
     * 帖子分页查询
     * @return
     */
    public String queryPage(int page,int size){


        try {
            PageModel pageModel = articalServer.pageArtical(page,size ,new Artical());
            return pageModel == null ? Result.success("没有数据") : Result.successModelObj(pageModel);

        } catch (Exception e) {

            e.printStackTrace();
            return Result.fial(e.getMessage());
        }

    }

    /**
     * 帖子内容查看
     * @return
     */
    public String queryArtical(Artical artical){
        try {
            Artical ar = this.articalServer.queryArtical(artical);
            return ar==null ? Result.fial("帖子不存在") : Result.successObj(ar);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fial(e.getMessage());
        }


    }



}
